001 /* 002 * Copyright 2004-2005 Niclas Hedhman. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 013 * implied. 014 * 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019 package net.dpml.util; 020 021 import java.util.HashMap; 022 023 /** 024 * Mimetype utility handler. 025 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 026 * @version 1.0.2 027 */ 028 public final class MimeTypeHandler 029 { 030 // ------------------------------------------------------------------------ 031 // static 032 // ------------------------------------------------------------------------ 033 034 /** 035 * Static mime type table of artifact types to mimetype strings. 036 */ 037 private static final HashMap MIME_TYPES = new HashMap(); 038 039 static 040 { 041 MIME_TYPES.put( "plugin", "text/x-dpml-plugin" ); 042 MIME_TYPES.put( "conf", "text/x-dpml-conf" ); 043 MIME_TYPES.put( "jar", "application/x-jar" ); 044 MIME_TYPES.put( "zip", "application/x-zip" ); 045 MIME_TYPES.put( "pdf", "application/pdf" ); 046 MIME_TYPES.put( "png", "image/png" ); 047 MIME_TYPES.put( "gif", "image/gif" ); 048 MIME_TYPES.put( "jpg", "image/jpg" ); 049 MIME_TYPES.put( "link", "application/x-dpml-link" ); 050 MIME_TYPES.put( "part", "application/x-dpml-part" ); 051 } 052 053 /** 054 * Return the mimetype given a artifact type. 055 * @param artifactType the artifact type such as "part", "jar", etc. 056 * @return the matching mimetype of null if unknown 057 */ 058 public static String getMimeType( String artifactType ) 059 { 060 return (String) MIME_TYPES.get( artifactType ); 061 } 062 063 /** 064 * Returns the number of MimeTypes that has been defined. 065 * 066 * Only for use with testcases. 067 * @return the known mimetype count 068 */ 069 public static int getMimeTypesSize() 070 { 071 return MIME_TYPES.size(); 072 } 073 074 // ------------------------------------------------------------------------ 075 // constructor 076 // ------------------------------------------------------------------------ 077 078 /** 079 * Disabled constructor. 080 */ 081 private MimeTypeHandler() 082 { 083 // disable 084 } 085 }